<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>

    // Symbol应用 消除魔术字符串: 
    // 魔术字符串指的是，在代码之中多次出现、与代码形成强耦合的某一个具体的字符串或者数值。风格良好的代码，应该尽量消除魔术字符串，改由含义清晰的变量代替

    var a = Symbol('calc')
    console.log(a)
    var a = Symbol('_calc')
    console.log(a)

    var calcOpt = {
        add: Symbol("+"),
        red: Symbol("-"),
        mul: Symbol("*"),
        div: Symbol("/"),
        mod: Symbol("%"),
    }


    Math[a] = function (a, opt, b) {
        if (opt === calcOpt.add) {
            return a + b
        } else if (opt === calcOpt.red) {
            return a - b
        } else if (opt === calcOpt.mul) {
            return a * b
        } else if (opt === calcOpt.div) {
            return a / b
        } else if (opt === calcOpt.mod) {
            return a % b
        }

    }


    console.log(Math[a](10, calcOpt.add, 20))
    console.log(Math[a](10, calcOpt.red, 20))
    console.log(Math[a](10, calcOpt.mul, 20))
    console.log(Math[a](10, calcOpt.div, 20))
    console.log(Math[a](10, calcOpt.mod, 20))
</script>

</html>